package com.wisemoresystem.seal.action.seal.news;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealNewService;
import com.wisemoresystem.seal.service.SealSetService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章 出厂 登记
 * 
 * @author Administrator
 *
 */
@Controller("sealNewsBack")
@Scope("prototype")
@RequestMapping("/ix/seal/news/engraving_back")
public class SealNewsEngravingBackAction extends ProjBaseAction {

	@Autowired
	private SealNewService sealnewService;
	@Autowired
	private SealSetService sealService;

	/**
	 * 印章出场登记列表
	 * 
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list() {

		List<Map<String, Object>> list = sealnewService
				.selectSealNewEngravingingList(page);

		ModelAndView mv = new ModelAndView("/jsp/seal/news/engraving_back/list");
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 登记印章的详细信息
	 * 
	 * @param sealnew_id
	 *            新章申请id
	 * @return
	 */
	@RequestMapping("/back_form")
	public ModelAndView back_form(String sealnew_id) {

		t_seal_new sealNew = (t_seal_new) oc.findObjById(sealnew_id,
				t_seal_new.class);
		t_seal_type sealType = (t_seal_type) oc.findObjById(
				sealNew.getSeal_type_id(), t_seal_type.class);
		t_seal_type_config sealTypeConfig = (t_seal_type_config) oc
				.findObjById(sealNew.getSeal_type_config_id(),
						t_seal_type_config.class);
		List<Map<String, Object>> userlist = sealService.selectSealUserList();

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/news/engraving_back/back_form");
		mv.addObject("sealNew", sealNew);
		mv.addObject("sealType", sealType);
		mv.addObject("sealTypeConfig", sealTypeConfig);
		mv.addObject("userlist", userlist);
		return mv;
	}

	/**
	 * 印章登记
	 * 
	 * @param sealnew_id
	 *            新章id
	 * @param flag
	 *            状态
	 * @param file_id
	 *            文件id
	 * @param save_user_id
	 * @param true_code
	 * @param note
	 *            登记备注
	 * @return
	 */
	@RequestMapping("/back")
	public ModelAndView back(String sealnew_id, String flag, String file_id,
			String save_user_id, String true_code, String note) {

		boolean islive = sealnewService.checkUniqueCode(sealnew_id, true_code);
		if (!islive) {
			super.setTipMsg("该编码已存在，请重新输入！", Tip.Type.error);
			ModelAndView mv = new ModelAndView(
					"redirect:back_form.htm?sealnew_id=" + sealnew_id);
			return mv;
		}

		// 出厂登记 还有上传图片,备注云云
		sealnewService.back(sealnew_id, flag, file_id, save_user_id, true_code,
				note);

		logT.logH("印章登记", t_seal_new.class, sealnew_id);

		this.setTipMsg("登记完成.");
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	@RequestMapping("/mark_list")
	public ModelAndView mark_list(String srh_name) {
		List<Map<String, Object>> list = sealnewService
				.selectSealNewEngravingingLogList(WebTools.getCurrentBankId(),
						srh_name, page);

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/news/engraving_back/mark_list");
		mv.addObject("list", list);
		return mv;
	}

}
